<%-- 
    Document   : param
    Created on : Mar 22, 2013, 11:17:45 AM
    Author     : thomasg
--%>

<%@ page import="java.sql.*" %>
<%@ include file="loginDetails.jsp" %>

<HTML>
<HEAD>
	<TITLE>Query Results Using JSP and Parameters</TITLE>
</HEAD>
<BODY>
<% 
try { // Load driver class
	Class.forName("com.mysql.jdbc.Driver");
}
catch (java.lang.ClassNotFoundException e) {
	System.err.println("ClassNotFoundException: " +e);
}
Connection con = null;
try { 
	
	con = DriverManager.getConnection(url+db, uid, pwd); 
	//defined in loginDetails.jsp
	
	Statement stmt = con.createStatement();
	
	//Read parameter:
	String manf = request.getParameter("manf");
	
	String SQLSt = "SELECT name,manf FROM Beers where manf='";	
	if (manf == null || manf.equals(""))
		manf = "Unknown";
	
        SQLSt = SQLSt + manf+"'"; 
	ResultSet rst = stmt.executeQuery(SQLSt);
	
	out.print("<TABLE border=1><TR><TH>Beer</TH>");
	out.println("<TH>Manufacturer</TH></TR>");

	while (rst.next()){ 
		out.println("<TR><TD>"+rst.getString("name")+
			"</TD>"+"<TD>"+rst.getString("manf")+"</TD></TR>");
	}
	out.println("</TABLE>");
	con.close();
}
catch (SQLException ex) { System.err.println(ex); }
finally{ 
	if (con != null)
	try
	{ con.close(); }
	catch (SQLException ex) { System.err.println(ex); }
}

%>
</BODY>
</HTML>